<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    防抖测试：<input type="text">
</body>
</html>
<script>
    function debounce(fun,wait=500) {
        let timeout = 0;
        return function (...args) {
            clearTimeout(timeout);
            timeout = setTimeout(() => {
                fun.apply(this,args)    
            }, wait);
        } 
    }

    const testDebounce = debounce(function(){
        console.log('打印输入框的值',this.value);
    },2000)

    const inp = document.querySelector('input');
    inp.addEventListener('input',testDebounce)
</script>